package com.itheima.manager_system.dao;

import com.itheima.manager_system.controller.StudentController;
import com.itheima.manager_system.domain.Student;
import com.itheima.manager_system.service.StudentService;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentDao {
    private static ArrayList<Student> list = new ArrayList<>();

    private StudentService studentService = new StudentService();
    private Scanner sc = new Scanner(System.in);
    //增
    public void addStudent() {
        StudentController studentController = new StudentController();
        list.add(studentController.inputStudent());
        System.out.println("添加成功");

    }

    //删
    public void removeStudent(String removeId) {
        int index = studentService.getIndex(removeId, list);
        list.remove(index);
        System.out.println("删除成功");

    }

    //改
    public void updateStudent(String updateId) {
        int index = studentService.getIndex(updateId, list);
        Student st = list.get(index);
        System.out.println("请输入名字");
        st.setName(sc.next());
        System.out.println("请输入年龄");
        st.setAge(sc.nextInt());
        System.out.println("请输入出生日期");
        st.setBirthday(sc.next());
        System.out.println("修改成功");


    }

    //查
    public void AllStudents() {
        if (list != null && list.size() != 0) {
            System.out.println("编号\t姓名\t年龄\t\t出生日期");
            for (Student s : list) {
                System.out.println(s.getId() + "\t" + s.getName() + "\t" + s.getAge() + "\t" + s.getBirthday());
            }
        } else {
            System.out.println("没有信息可供查询");
        }

    }


    public ArrayList<Student> getList() {
        return list;
    }


}
